/**
 * Created with JetBrains PhpStorm.
 * User: shaoshuai
 * Date: 12-7-21
 */

FlyFight.model.Connection = Zen.extend(Zen.Model, {
    running: false,
    initModel: function () {
        this.addEvents(
            'event-received'
        );
    },
    start: function () {
        var that = this;
        var comet = function () {
            if (that.running) {
                that.ajax({
                    url: 'server/comet.php',
                    dataType: 'json',
                    success: function (result) {
                        var data = result.data;
                        that.fireEvent('event-received', data['type'], data['data']);
                        comet();
                    }
                });
            }
        };
        this.running = true;
        comet();
    },
    stop: function () {
        this.running = false;
    }
});

FlyFight.mode.Connection.ONLINE_LIST_CHANGE = 1;
